
class P836 {

	private static int[][] matrix;

	private static int n;

	private static int[][] sumMatrix;


	public static void main(String[] args) {
		try {
			int cases = Integer.parseInt(readLn());

			readLn();
			String line = null;
			n = 30;
			matrix = new int[n][n];
			sumMatrix = new int[n][n];

			for (int l = 0; l < n; l++) {
				line = readLn();
				n = line.length();
				for (int c = 0; c < n; c++) {
					int i = (int) (line.charAt(c) - '0');
					matrix[l][c] = (i == 0) ? -100000 : i;
				}
			}

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					sumMatrix[i][j] = getSum(i, j);
				}
			}

			int maxSum = Integer.MIN_VALUE;

			// and if you have this table the sum of the rectangle for
			// exmple
			// form 2,2 to 4,5 is equal to :
			// B[4,5]-B[4,1]-B[1,5]+B[1,1]

			for (int i0 = 0; i0 < n; i0++) {
				for (int j0 = 0; j0 < n; j0++) {
					for (int iF = i0; iF < n; iF++) {
						for (int jF = j0; jF < n; jF++) {
							int sum = sumMatrix[iF][jF] - ((j0 - 1 == -1) ? 0 : sumMatrix[iF][j0 - 1])
									- ((i0 - 1 == -1) ? 0 : sumMatrix[i0 - 1][jF])
									+ ((i0 - 1 == -1 || j0 - 1 == -1) ? 0 : sumMatrix[i0 - 1][j0 - 1]);
							if (sum > maxSum) {
								maxSum = sum;
							}
						}
					}
				}
			}
			System.out.println(maxSum < 0 ? 0 : maxSum);

			for (int k = 1; k < cases; k++) {
				System.out.println();
				readLn();
				line = null;
				n = 30;
				matrix = new int[n][n];
				sumMatrix = new int[n][n];

				for (int l = 0; l < n; l++) {
					line = readLn();
					n = line.length();
					for (int c = 0; c < n; c++) {
						int i = (int) (line.charAt(c) - '0');
						matrix[l][c] = (i == 0) ? -100000 : i;
					}
				}

				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						sumMatrix[i][j] = getSum(i, j);
					}
				}

				maxSum = Integer.MIN_VALUE;

				// and if you have this table the sum of the rectangle for
				// exmple
				// form 2,2 to 4,5 is equal to :
				// B[4,5]-B[4,1]-B[1,5]+B[1,1]

				for (int i0 = 0; i0 < n; i0++) {
					for (int j0 = 0; j0 < n; j0++) {
						for (int iF = i0; iF < n; iF++) {
							for (int jF = j0; jF < n; jF++) {
								int sum = sumMatrix[iF][jF] - ((j0 - 1 == -1) ? 0 : sumMatrix[iF][j0 - 1])
										- ((i0 - 1 == -1) ? 0 : sumMatrix[i0 - 1][jF])
										+ ((i0 - 1 == -1 || j0 - 1 == -1) ? 0 : sumMatrix[i0 - 1][j0 - 1]);
								if (sum > maxSum) {
									maxSum = sum;
								}
							}
						}
					}
				}
				System.out.println(maxSum < 0 ? 0 : maxSum);

			}
		} catch (Exception e) {
			while (true) {

			}
		}
	}


	// the B[i,j] = sum (from 1 to i and form 1 to j of A)
	private static int getSum(int iF, int jF) {
		int sum = 0;
		for (int i = 0; i <= iF; i++) {
			for (int j = 0; j <= jF; j++) {
				sum += matrix[i][j];
			}
		}

		return sum;
	}


	private static int getMaxSumOf(int i0, int j0) {
		int maxSum = Integer.MIN_VALUE;
		for (int i = i0; i < n; i++) {
			for (int j = i0; j < n; j++) {
				int sum = 0;
				for (int l = i0; l <= i; l++) {
					for (int m = j0; m <= j; m++) {
						sum += matrix[l][m];
					}
				}
				if (sum > maxSum) {
					maxSum = sum;
				}
			}
		}
		return maxSum;
	}


	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

}
